package com.dji.sdk.self.internal.view;

import android.app.Service;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.dji.sdk.self.R;
import com.dji.sdk.self.internal.controller.DJISampleApplication;
import com.dji.sdk.self.internal.controller.MainActivity;

public class UxView extends LinearLayout implements View.OnClickListener {

    private Context mContext;
    private Button btnFlightController;
    private Button btnFlightSetting,btnSensorSetting,btnRemoteControllerSetting,btnGraphSetting,btnBatterySetting,btnNormalSetting,btnCross;
    private TextView tvTitle;
    private View view;
    private Toolbar mToolbar;
    public UxView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initUI(mContext);
    }

    private void initUI(Context context) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.ux_settings,this,true);
        mToolbar = view.findViewById(R.id.tb_setting);
        btnFlightSetting = view.findViewById(R.id.btn_flight_setting);
        btnSensorSetting = view.findViewById(R.id.btn_sensor_setting);
        btnRemoteControllerSetting = view.findViewById(R.id.btn_remote_controller_setting);
        btnGraphSetting = view.findViewById(R.id.btn_graph_setting);
        btnBatterySetting = view.findViewById(R.id.btn_battery_setting);
        btnNormalSetting = view.findViewById(R.id.btn_normal_setting);
        tvTitle = view.findViewById(R.id.tv_title);
        mToolbar.inflateMenu(R.menu.setting_menu);

        btnFlightSetting.setOnClickListener(this);
        btnSensorSetting.setOnClickListener(this);
        btnRemoteControllerSetting.setOnClickListener(this);
        btnGraphSetting.setOnClickListener(this);
        btnBatterySetting.setOnClickListener(this);
        btnNormalSetting.setOnClickListener(this);
    }
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        DJISampleApplication.getEventBus().post(new MainActivity.RequestStartFullScreenEvent());
    }

    @Override
    protected void onDetachedFromWindow() {
        DJISampleApplication.getEventBus().post(new MainActivity.RequestEndFullScreenEvent());
        super.onDetachedFromWindow();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_flight_setting:
                freshTitle("飞控参数设置");
                break;
            case R.id.btn_sensor_setting:
                freshTitle("感知设置");
                break;
            case R.id.btn_remote_controller_setting:
                freshTitle("遥控器功能设置");
                break;
            case R.id.btn_graph_setting:
                freshTitle("图传设置");
                break;
            case R.id.btn_battery_setting:
                freshTitle("智能电池信息");
                break;
            case R.id.btn_normal_setting:
                freshTitle("通用设置");
                break;
        }
    }

    public boolean onOptionsItemSelected(MenuItem menuItem){
        switch (menuItem.getItemId()){
            case R.id.back:
                freshView();
                break;
        }
        return true;
    }

    public void freshTitle(String s){
        tvTitle.setText(s);
    }
    public void freshView(){
        this.setVisibility(View.GONE);
    }
}
